<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="../head.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>babasport-list</title>
    <script type="text/javascript">
        //上下架商品
        function isShows(flag) {
            //请至少选择一个
            var size = $("input[name='ids']:checked").size();
            if (size == 0) {
                alert("请至少选择一个");
                return;
            }
            //你确定上下架吗
            if (!confirm("你确定上架或者下架吗")) {
                return;
            }
            //提交 Form表单
            $("#jvForm").attr("action", "isShow.do?flag=" + flag);
            $("#jvForm").attr("method", "post");
            $("#jvForm").submit();

        }


        //加载商品的品牌
        $(function () {
            $.get("/console/brand/query.do", function (data) {
                // alert(data);
                var data = eval(data);
                for (var i in data) {
                    if ('${brandId}' == data[i].id) {
                        $("select[name='brandId']").append("<option selected='selected' value='" + data[i].id + "'>" + data[i].name + "</option>");
                    } else {
                        $("select[name='brandId']").append("<option value='" + data[i].id + "'>" + data[i].name + "</option>");
                    }
                }
            }, "json");
        })

        function optDelete() {
            var sizes = $("input[name='ids']:checked").size();
            if (sizes == 0) {
                alert("请至少选择一项");
                return;
            }
            if (!confirm("确定删除吗？")) {
                return;
            }
            $("#jvForm")[0].action = "doDelete.do";
            $("#jvForm").submit();
        }

        function checkbox(name, checked) {
            $("input[name='" + name + "']").attr("checked", checked);
        }

        //删除当个商品
        function de() {
            var ss = $("input[name='ids']").val();
            $("#jvForm")[0].action = "doDelete.do?ids=" + ss;
            $("#jvForm").submit();
        }

    </script>
</head>
<body>
<div class="box-positon">
    <div class="rpos">当前位置: 商品管理 - 列表</div>
    <form class="ropt">
        <input class="add" type="button" value="添加" onclick="window.location.href='showAdd.do'"/>
    </form>
    <div class="clear"></div>
</div>
<div class="body-box">
    <form action="list.do" method="get" style="padding-top:5px;">
        名称: <input type="text" name="name" value="${name}"/>
        <select name="brandId">
            <option value="">请选择品牌</option>
            <%--  <option value="1">依琦莲</option>
              <option value="2">凯速（KANSOON）</option>--%>
        </select>
        <select name="isShow">
            <option value="1">上架</option>
            <option selected="selected" value="0">下架</option>
        </select>
        <script type="text/javascript">

            $("select[name='isShow']").val('${isShow}');
        </script>
        <input type="submit" class="query" value="查询"/>
    </form>
    <form id="jvForm" method="post">
        <input name="name" value="${name}" type="hidden"/>
        <input name="brandId" value="${brandId}" type="hidden"/>
        <input name="pageNum" value="${page.pageNum}" type="hidden"/>
        <input name="isShow" value="${isShow}" type="hidden"/>
        <table cellspacing="1" cellpadding="0" width="100%" border="0" class="pn-ltable">
            <thead class="pn-lthead">
            <tr>
                <th width="20"><input type="checkbox" onclick="Pn.checkbox('ids',this.checked)"/></th>
                <th>商品编号</th>
                <th>商品名称</th>
                <th>图片</th>
                <th width="4%">新品</th>
                <th width="4%">热卖</th>
                <th width="4%">推荐</th>
                <th width="4%">上下架</th>
                <th width="12%">操作选项</th>
            </tr>
            </thead>
            <tbody class="pn-ltbody">
            <c:forEach items="${page.result}" var="product">
                <tr bgcolor="#ffffff" onmouseover="this.bgColor='#eeeeee'" onmouseout="this.bgColor='#ffffff'">
                    <td><input type="checkbox" name="ids" value="${product.id}"/></td>
                    <td>${product.id}</td>
                    <td align="center">${product.name}</td>
                    <td align="center">
                            <%--显示多个图片,可以调整begin和end的参数来实现图片数量的调整--%>
                        <c:forTokens items="${product.imgUrl}" delims="," var="im" begin="0" end="1">
                            <img width="50" height="50" src="${im}"/>
                        </c:forTokens>
                    </td>
                    <td align="center"><c:if test="${product.isNew==1}">是</c:if><c:if
                            test="${product.isNew==0}">否</c:if></td>
                    <td align="center"><c:if test="${product.isHot==1}">是</c:if><c:if
                            test="${product.isHot==0}">否</c:if></td>
                    <td align="center"><c:if test="${product.isCommend==1}">是</c:if><c:if
                            test="${product.isCommend==0}">否</c:if></td>
                    <td align="center"><c:if test="${product.isShow==1}">上架</c:if><c:if
                            test="${product.isShow==0}">下架</c:if></td>
                    <td align="center">
                        <a href="#" class="pn-opt">查看</a> | <a href="showEdit.do?productId=${product.id}"
                                                               class="pn-opt">修改</a> | <a href="#"
                                                                                          onclick="if(confirm('您确定删除吗？')) {de()}"
                                                                                          class="pn-opt">删除</a>
                        | <a href="../sku/list.do?productId=${product.id}" class="pn-opt">库存</a>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
        <div class="page pb15">
	<span class="r inb_a page_b">
	
		<font size="2"><a
                href="list.do?&amp;isShow=0&amp;pageNum=1&name=${name}&brandId=${brandId}&isShow=${isShow}">首页</a></font>
        <c:if test="${page.pageNum-1>=1}">
            <font size="2"><a
                    href="list.do?&amp;isShow=0&amp;pageNum=${page.pageNum-1}&name=${name}&brandId=${brandId}&isShow=${isShow}">上一页</a></font>
        </c:if>

    <c:forEach begin="${page.begin}" end="${page.end}" var="pn">
        <c:if test="${page.pageNum==pn}"><strong>${pn}</strong></c:if>
        <c:if test="${page.pageNum!=pn}"><a
                href="list.do?&amp;isShow=0&amp;pageNum=${pn}&name=${name}&brandId=${brandId}&isShow=${isShow}">${pn}</a></c:if>

    </c:forEach>


	<c:if test="${page.pageNum+1<=page.pages}">
        <font size="2"><a
                href="list.do?&amp;isShow=0&amp;pageNum=${page.pageNum+1}&name=${name}&brandId=${brandId}&isShow=${isShow}">下一页</a></font>
    </c:if>
        <c:if test="${page.pageNum!=page.pages}">
            <a href="list.do?&amp;isShow=0&amp;pageNum=${page.pages}&name=${name}&brandId=${brandId}&isShow=${isShow}"><font
                    size="2">尾页</font></a>
        </c:if>


	
		共<var>${page.pages}</var>页 到第<input type="text" size="3" id="PAGENO"/>页 <input type="button"
                                                                                       onclick="javascript:window.location.href = 'list.do?&amp;isShow=0&amp;pageNum=' + $('#PAGENO').val()+'&name=${name}&brandId=${brandId}&isShow=${isShow}' "
                                                                                       value="确定" class="hand btn60x20"
                                                                                       id="skip"/>
	
	</span>
        </div>
        <div style="margin-top:15px;"><input class="del-button" type="button" value="删除" onclick="optDelete();"/><input
                class="add" type="button" value="上架" onclick="isShows(1);"/><input class="del-button" type="button"
                                                                                   value="下架" onclick="isShows(0);"/>
        </div>
    </form>
</div>
</body>
